package com.xstablet.activity;

import android.content.pm.ActivityInfo;
import android.widget.Button;
import android.widget.FrameLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.lib.app.ARouterPathUtils;
import com.lib.fastkit.db.shared_prefrences.SharedPreferenceManager;
import com.lib.fastkit.db.shared_prefrences.interfaces.UserCacheInterface;
import com.lib.fastkit.utils.status_bar.StatusBarUtil;
import com.lib.ui.activity.BaseAppActivity;
import com.xstablet.R;
import com.xstablet.fragment.FragmentGuide;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.OnClick;


@Route(path = ARouterPathUtils.Tablet_App_GuideActivity)
public class GuideActivity extends BaseAppActivity {

    @BindView(R.id.mViewPager)
    ViewPager mViewPager;
    @BindView(R.id.btn_start)
    Button btnStart;
    @BindView(R.id.f_parent)
    FrameLayout f_parent;

    private DemandAdapter mDemandAdapter;

    @Override
    protected void onCreateView() {

        StatusBarUtil.statusBarTintColor(this, getResources().getColor(R.color.white));

        for (int i = 0; i < 3; i++) {

            FragmentGuide fragmentGuide = new FragmentGuide(i + 1);
            fragments.add(fragmentGuide);

        }

        mDemandAdapter = new DemandAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mDemandAdapter);
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mViewPager.setOffscreenPageLimit(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @Override
    protected void onResume() {
        /**
         * 设置为横屏
         */
        if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
        super.onResume();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_guide;
    }

    /**
     * 适配器
     */
    private List<Fragment> fragments = new ArrayList<>();

    public class DemandAdapter extends FragmentPagerAdapter {


        public DemandAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {

            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

    }

    @OnClick(R.id.btn_start)
    public void onViewClicked() {

        ARouter.getInstance().build(ARouterPathUtils.Tablet_User_LoginActivity).navigation();

        UserCacheInterface userCacheInterface = SharedPreferenceManager.getInstance(this).getUserCache();
        userCacheInterface.setShow(true);

    }
}
